package org.jumiz.telnet.command;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;

/**
 *
 */
public class MessageResponse {

    private static ConcurrentHashMap<String, LinkedBlockingQueue<String>> messages = new ConcurrentHashMap<>();

    public static void putMessage(String connectionId, String message) {
        LinkedBlockingQueue queue = messages.get(connectionId);
        if (queue == null) {
            queue = new LinkedBlockingQueue<String>();
            messages.put(connectionId, queue);
        }
        queue.offer(message);
    }

    public static String getMessage(String connectionId) {
        return messages.get(connectionId).poll().toString();
    }

    public static boolean hasMessage(String connectionId) {
        return messages.get(connectionId).size() > 0;
    }

    public static void remote(String connectionId) {
        messages.remove(connectionId);
    }
}
